package leetcode.code2116;

import java.util.HashMap;
import java.util.Map;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public boolean canBeValid(String s, String locked) {
//    	s = "))()))", locked = "010100"
		int l = 0, change = 0;
		for (int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			char lock = locked.charAt(i);
			if (c == '(') {
				if (lock == '0' && l > 0) {
					l--;
					change++;
				} else {
					l++;
				}
			} else {
				if (lock == '0') {
					if (l == 0) {
						l++;
					} else {
						l--;
						change++;
					}
				} else {
					if (l == 0 && change == 0) {
						return false;
					}
					if (l > 0) {
						l--;
					} else {
						change--;
						l++;
					}
				}
			}
		}
		return l == 0;
	}

	@Override
	public void debug4() {
		H.compare(true, this.canBeValid("())()))()(()(((())(()()))))((((()())(())",
				"1011101100010001001011000000110010100101"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
